﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp25
{
    class Program
    {
        static void Main(string[] args)
        {
           var conString = "server=.;database=ProfessionalTable;uid=sa;pwd=123456";
            SqlConnection sqlConnection = new SqlConnection(conString);



            sqlConnection.Open();

            var cmdString = "select*from Student ";

            var insertString =
                string.Format("insert into Student (Id,Student,TeacherId)values('{0}','{1}','{2}')","6", "7", "66");//增加
            var updateString = "update Student set TeacherId='77'where id=2";//更新
            SqlCommand  command = new SqlCommand(updateString, sqlConnection);

            var res = command.ExecuteNonQuery();

            Console.WriteLine(res);

          /*  var reader = command.ExecuteReader();
            Console.WriteLine("{0}\t{1}\t{2}", "Id", "学生编号", "老师编号");
            while (reader.Read())
            {
                Console.WriteLine("{0}\t{1}\t{2}", reader[0], reader[1], reader[2]);
            }
*/


            DataTable dataTable = new DataTable();
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(cmdString, conString);
            sqlDataAdapter.Fill(dataTable);

            Console.WriteLine();

           


           sqlConnection.Close();
        }
    }
}
